package com.example.book_libapp;

import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class CheckInternetAcces {

	Activity _current_activity;

	public CheckInternetAcces(Activity _current_activity) {
		this._current_activity = _current_activity;
	}

	public static boolean isOnline(Activity _current_activity) {
		ConnectivityManager cm = (ConnectivityManager) _current_activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getActiveNetworkInfo();
		if (netInfo != null && netInfo.isConnectedOrConnecting()) {
			return true;
		}
		return false;

	}

	public static boolean isWifi(Activity _current_activity) {
		ConnectivityManager cm = (ConnectivityManager) _current_activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		if (netInfo != null
				&& netInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
			return true;
		}
		return false;
	}

	public static boolean isMobile(Activity _current_activity) {
		ConnectivityManager cm = (ConnectivityManager) _current_activity
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = cm
				.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (netInfo != null
				&& netInfo.getState().equals(NetworkInfo.State.CONNECTED)) {
			return true;
		}
		return false;
	}

}